/*
* @Author: ludynice
* @Date:   2017-09-18 22:53:42
* @Last Modified by:   ludynice
* @Last Modified time: 2017-09-24 13:36:10
*/
'use strict';
require('./index.css');
var _main = require('util/main.js');
var header = {
    init : function(){
        this.onLoad();
        this.bindEvent();
        return this;
    },
    onLoad : function(){
        var keyword = _main.getUrlParam('keyword');
        //如果keyword存在，则回填输入框
        if(keyword){
            $('#search-input').val(keyword);
        };
    },
    bindEvent : function(){
        var _this = this;
        $('#search-btn').click(function(){
            _this.searchSubmit();
        });
        //输入回车后，做搜索提交
        $('#search-input').keyup(function(e){
            //13是回车键的keyCode
            if(e.keyCode === 13){
                _this.searchSubmit();
            }
        });
    },
    searchSubmit : function(){
        var keyword = $.trim($('#search-input').val());
        if(keyword){
            window.location.href = './list.html?keyword=' + keyword;
        }else{
            _main.goHome();
        }
    }
};
module.exports = header.init();